﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMTP.Master" AutoEventWireup="true" CodeBehind="User.aspx.cs" Inherits="tracnghiemonline2.User" %>

<%@ Import Namespace="DataAccess" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Ajax/JS/User.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="w3-row" id="main-admin">
        <header class="w3-padding w3-large w3-center w3-teal">QUẢN LÝ NGƯỜI DÙNG</header>
        <div class="w3-row">
            <div class="w3-third w3-padding">
                <label class="w3-teal" style="padding: 1% 3%" title="Tìm kiếm"><i class="fa fa-search"></i></label>
                <input id="find_user_by_name" type="text" placeholder="Tìm theo username, họ tên, mã HV" style="width: 70%; padding: 0.5%" />
            </div>
            <div class="w3-quarter w3-padding">
                <label class="w3-teal" style="padding: 1% 3%" title="Lọc cấp độ"><i class="fa fa-filter"></i></label>
                <select style="padding: 1.1%" id="find_by_level">
                    <option selected="selected" value="">Chọn cấp độ</option>
                    <%var get_level = new TblUserRoleController().FetchAll().Skip(1);
                      foreach (TblUserRole level in get_level)
                      {%>
                    <option value="<%=level.RoleId %>"><%=level.RoleName %></option>
                    <%} %>
                </select>
                <a id="btn_level_edit" class="w3-btn w3-teal" onclick="document.getElementById('level_edit').style.display='block'" style="margin-bottom: 3px; display: none" title="Tùy chọn"><i class="fa fa-cogs"></i></a>
                <a onclick="document.getElementById('level_add').style.display='block'" class="w3-btn w3-teal" style="margin-bottom: 3px" title="Thêm Quyền"><i class="fa fa-plus"></i></a>
            </div>
            <div class="w3-third w3-padding">
                <a style="display: none" id="add_member" onclick="document.getElementById('add-student-modal').style.display = 'block'" class="w3-btn w3-teal"><i class="fa fa-plus"></i>&nbsp;<i class="fa fa-user"></i>&nbsp;Thêm học viên</a>
                <%-- Thêm học viên --%>
                <div id="add-student-modal" class="w3-modal">
                    <div class="sign-in-modal w3-modal-content w3-card-8 w3-animate-bottom" style="width: 45%">
                        <header class="w3-padding w3-center w3-teal">
                            <span class="w3-large">THÊM HỌC VIÊN</span>
                        </header>
                        <div id="add_student_form" class="w3-row w3-padding w3-text-black">
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-text-teal">Những thông tin có đánh dấu <i class="fa fa-star w3-text-red w3-small"></i>&nbsp;là bắt buộc nhập.</span><br />
                                <span id="error_msg" class="w3-text-red"></span>
                            </div>
                            <div id="check_number" class="w3-hide">0</div>
                            <div id="check_username" class="w3-hide">0</div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Mã học viên</span>
                                <input class="w3-col l4" id="txt_studentnumber" maxlength="10" name="fullname" type="text" placeholder="Nhập mã học viên" autofocus="autofocus" required="required" />
                                <span class="w3-col l4 w3-text-red w3-padding-top" id="error_msg_number" style="display:none">&nbsp;Mã học viên đã tồn tại</span>
                            </div>
                            <div class="w3-row w3-padding-bottom" style="display: none" id="exits_username"></div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Tên đăng nhập</span>
                                <input class="w3-col l4" id="txt_user_username" maxlength="15" name="username" type="text" placeholder="Nhập tên đăng nhập" autofocus="autofocus" required="required" />
                                <span class="w3-col l4 w3-text-red w3-padding-top" id="error_msg_username" style="display:none">&nbsp;Tên đăng nhập đã tồn tại</span>
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Họ tên</span>
                                <input class="w3-col l8" id="txt_fullname" maxlength="40" name="fullname" type="text" placeholder="Nhập họ tên đầy đủ" autofocus="autofocus" required="required" />
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Ngày sinh</span>
                                <div class="w3-col l2 w3-padding-right">
                                    <select id="reg-day">
                                        <%for (int i = 1; i <= 31; i++)
                                          { %>
                                        <option value="<%=i %>"><%=i %></option>
                                        <%} %>
                                    </select>
                                </div>
                                <div class="w3-col l2 w3-padding-right">
                                    <select id="reg-month">
                                        <%for (int i = 1; i <= 12; i++)
                                          { %>
                                        <option value="<%=i %>"><%=i %></option>
                                        <%} %>
                                    </select>
                                </div>
                                <div class="w3-col l3 w3-padding-right">
                                    <select id="reg-year">
                                        <%
                                            int get_year = DateTime.Now.Year - 5;
                                            for (int i = get_year; i >= get_year - 40; i--)
                                            {
                                        %>
                                        <option value="<%=i %>"><%=i %></option>
                                        <%} %>
                                    </select>
                                </div>
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <div class="w3-third w3-text-teal w3-padding-top"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Giới tính</div>
                                <div class="radio w3-third">
                                    <input type="radio" name="sex" value="1" checked="checked" id="reg-male" /><label for="reg-male">Nam</label>&nbsp;
                                    <input type="radio" name="sex" value="0" id="reg-female" /><label for="reg-female">Nữ</label>
                                </div>
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Email</span>
                                <input class="w3-col l8" id="txt_user_email" maxlength="40" name="email" type="email" placeholder="Nhập email" autofocus="autofocus" required="required" />
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Số điện thoại</span>
                                <input class="w3-col l8" id="txt_user_phone" maxlength="12" name="phone" type="text" placeholder="Nhập số điện thoại" autofocus="autofocus" required="required" />
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Quê quán</span>
                                <div class="w3-third w3-padding-right">
                                    <select id="ddl_province">
                                        <option value="0" selected="selected">Tỉnh</option>
                                        <%foreach (TblProvince province in (from p in new TblProvinceController().FetchAll() orderby p.ProvinceName ascending select p))
                                          {%>
                                        <option value="<%=province.Id %>"><%=province.ProvinceName %></option>
                                        <%} %>
                                    </select>
                                </div>
                                <div class="w3-third">
                                    <select id="ddl_city">
                                    </select>
                                </div>
                            </div>
                            <div class="w3-row w3-padding-bottom">
                                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Địa chỉ</span>
                                <input class="w3-col l8" id="txt_address" maxlength="100" name="fullname" type="text" placeholder="Địa chỉ thường trú" autofocus="autofocus" required="required" />
                            </div>
                            <div class="w3-row">
                                <div id="sign-in-user" class="w3-half"><a href="javascript:;" class="w3-btn w3-teal" style="width: 100%"><i class="fa fa-save"></i>&nbsp;Lưu</a></div>
                                <div class="w3-half"><a href="javascript:;" class="w3-btn w3-red" style="width: 100%" onclick="document.getElementById('add-student-modal').style.display='none'">&times;&nbsp;Huỷ</a></div>
                            </div>
                        </div>
                    </div>
                </div>

                <%-- Sửa học viên --%>
                <div id="edit_user_modal" class="w3-modal">
                    
                </div>

            </div>
        </div>
        <div class="w3-responsive">
            <table id="user_show" class="staff-table w3-table w3-small w3-striped w3-bordered w3-border">
                <tr class="w3-teal">
                    <th>Ảnh</th>
                    <th>Mã HV</th>
                    <th>Tên đăng nhập</th>
                    <th>Quyền</th>
                    <th>Họ tên</th>
                    <th>Ngày sinh</th>
                    <th>Giới tính</th>
                    <th>SĐT</th>
                    <th>Email</th>
                    <th>Kích hoạt</th>
                    <th>Xóa</th>
                    <th>Sửa</th>
                </tr>
                <%
                    var get_user = (from p in new TblUserController().FetchAll() orderby p.UserId descending where p.UserId != 0 select p);
                    foreach (TblUser user in get_user)
                    {
                %>
                <tr id="user<%=user.UserId %>" class="user">
                    <td class="w3-hide user_id"><%=user.UserId %></td>
                    <td class="staff-img">
                        <img src="../Content/avatar/<%=user.Avatar %>" class="w3-circle" /></td>
                    <td><%=user.NumberStudy %></td>
                    <td><%=user.UserName %></td>
                    <td>
                        <select style="padding: 1.1%" class="change_level">
                            <%
                        foreach (TblUserRole role in get_level)
                        { %>
                            <%if (user.UserLevel == role.RoleId)
                              {%>
                            <option value="<%=role.RoleId %>" selected="selected"><%=role.RoleName %></option>
                            <%}
                              else
                              { %>
                            <option value="<%=role.RoleId %>"><%=role.RoleName %></option>
                            <%}
                        } %>
                        </select>
                    </td>
                    <td><%=user.FullName %></td>
                    <td><%=DateTime.Parse(user.BirthDay.ToString()).Day+"/"+DateTime.Parse(user.BirthDay.ToString()).Month+"/"+DateTime.Parse(user.BirthDay.ToString()).Year %></td>
                    <td><%if (user.Sex == true)
                          { %>Nam<%}
                          else
                          { %>Nữ<%} %></td>
                    <td><%=user.Phone %></td>
                    <td><%=user.Email %></td>
                    <%if (user.Active == true)
                      {%>
                    <td class="option-btn">
                        <i class="on2 fa fa-toggle-on w3-text-teal w3-animate-opacity"></i>
                    </td>
                    <%}
                      else
                      { %>
                    <td class="option-btn">
                        <i class="on2 fa fa-toggle-on w3-text-red w3-animate-opacity fa-rotate-180 off "></i>
                    </td>
                    <%} %>
                    <td class="option-btn"><i onclick="document.getElementById('xoanhanvien').style.display = 'block'" class="user_del fa fa-trash"></i></td>
                    <td class="option-btn"><i class="fa fa-wrench user_edit"></i></td>
                </tr>
                <%} %>
            </table>
        </div>
    </div>
    <div id="xoanhanvien" class="w3-modal">
        <div id="del_id" class="w3-hide"></div>
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal" style="width: 60%">
            <header class="w3-padding w3-center">
                <span onclick="document.getElementById('xoanhanvien').style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-xlarge">Bạn có chắc chắn muốn xóa người dùng này ?</p>
            </header>
            <div class="w3-row w3-padding w3-center">
                <a id="btn_user_del_yes" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-trash"></i>&nbsp;Xóa</a>
                <a onclick="document.getElementById('xoanhanvien').style.display='none'" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-times"></i>&nbsp;Hủy</a>
            </div>
        </div>
    </div>
    <div id="level_add" class="w3-modal">
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal" style="width: 30%">
            <header class="w3-padding w3-center">
                <span onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-xlarge">Thêm mới quyền</p>
            </header>
            <div class="w3-padding w3-row">
                <input type="text" id="txt_level_add" required="required" placeholder="Tên Quyền" autofocus="autofocus" style="width: 100%; padding: 0.5%; color: black" />
            </div>
            <div class="w3-row w3-padding w3-center">
                <a id="btn_level_add" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-save"></i>&nbsp;Lưu</a>
            </div>
        </div>
    </div>
    <div id="level_edit" class="w3-modal">
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal" style="width: 30%">
            <header class="w3-padding w3-center">
                <span onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-xlarge">Chỉnh sửa Quyền</p>
            </header>
            <div class="w3-padding w3-row">
                <input type="text" required="required" value="" id="txt_level_edit" placeholder="Tên quyền" autofocus="autofocus" style="width: 100%; padding: 0.5%; color: black" />
            </div>
            <div class="w3-row w3-padding w3-center">
                <a id="btn_level_edited" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-save"></i>&nbsp;Lưu</a>
                <a id="btn_level_del" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-trash"></i>&nbsp;Xóa</a>
            </div>
        </div>
    </div>
    <div id="level" class="w3-modal">
        <div id="confirm_id_user" class="w3-hide"></div>
        <div id="confirm_level_user" class="w3-hide"></div>
        <div class="w3-modal-content w3-animate-top w3-card-8 w3-teal" style="width: 30%">
            <header class="w3-padding w3-center">
                <span onclick="document.getElementById('level').style.display='none'" class="w3-closebtn">&times;</span>
                <p class="w3-xlarge">Xác nhận</p>
            </header>
            <div class="w3-row w3-padding w3-center">
                <a id="level_yes" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-check w3-small"></i>&nbsp;Đồng ý</a>
                <a onclick="document.getElementById('level').style.display='none'" class="w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-times"></i>&nbsp;Hủy</a>
            </div>
        </div>
    </div>
</asp:Content>
